package com.doit.demo02;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class Single_Thread_Server {
    public static void main(String[] args) throws IOException {
        System.out.println("单线程服务器启动");
        ServerSocket serverSocket = new ServerSocket(6666);
        Socket accept = serverSocket.accept();//叉车
        try {
            BufferedInputStream bis = new BufferedInputStream(accept.getInputStream());
            FileOutputStream fis = new FileOutputStream(System.currentTimeMillis() + ".jpg");
            BufferedOutputStream bos = new BufferedOutputStream(fis);
            byte[] b = new byte[1024 * 8];
            int len;
            while ((len=bis.read(b))!=-1){
                bos.write(b,0 ,len );
            }

            System.out.println("等待中");
            OutputStream out = accept.getOutputStream();
            out.write("上传成功".getBytes());
            out.close();

            bos.close();
            bis.close();
            accept.close();
            System.out.println("文件上传已保存");
        }catch (IOException e){
            e.printStackTrace();
        }
    }
}
